package com.mpyy.handler.purchase;

import com.alibaba.fastjson.JSON;
import com.mpyy.pojo.PurchaseStock;
import com.mpyy.pojo.PurchaseStockDesc;
import com.mpyy.pojo.SaleOrderDesc;
import com.mpyy.pojo.SupplierInfo;
import com.mpyy.service.purchase.SupplierServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SupplierController {
    @Autowired
    @Qualifier(value = "supplierServiceImpl")
    private SupplierServiceInter supplierServiceInter;

    /*供货商选择*/
    @RequestMapping(value = {"/searchSupplierInfoController"})
    @ResponseBody
    public String searchSupplierInfoController(SupplierInfo supplierInfo){
        List<SupplierInfo> supplierInfos = supplierServiceInter.searchSupplierInfo(supplierInfo);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",supplierInfos.size());
        map.put("data",supplierInfos);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*往来财务列表*/
    @RequestMapping(value = {"/searchFinanceController"})
    @ResponseBody
    public String searchFinanceController(PurchaseStock purchaseStock){
        System.out.println("purchaseStock="+purchaseStock);
        List<PurchaseStock> purchaseStocks = supplierServiceInter.searchFinance(purchaseStock);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",purchaseStocks.size());
        map.put("data",purchaseStocks);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*往来财务列表详情*/
    @RequestMapping(value = {"/searchFinanceDescController"})
    @ResponseBody
    public String searchFinanceDescController(PurchaseStockDesc purchaseStockDesc){
        System.out.println("purchaseStockDesc="+purchaseStockDesc);
        List<PurchaseStockDesc> purchaseStockDescs = supplierServiceInter.searchFinanceDesc(purchaseStockDesc);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",purchaseStockDescs.size());
        map.put("data",purchaseStockDescs);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*汇总表*/
    @RequestMapping(value = {"/searchcollectController"})
    @ResponseBody
    public String searchCollectController(PurchaseStockDesc purchaseStockDesc, SupplierInfo supplierInfo , PurchaseStock purchaseStock){
        purchaseStockDesc.setSupplierInfo(supplierInfo);
        purchaseStockDesc.setPurchaseStock(purchaseStock);
        System.out.println("purchaseStockDesc="+purchaseStockDesc);
        List<PurchaseStockDesc> searchcollect = supplierServiceInter.searchcollect(purchaseStockDesc);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",searchcollect.size());
        map.put("data",searchcollect);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*流水表*/
    @RequestMapping(value = {"/searchStreamController"})
    @ResponseBody
    public String searchStreamController(PurchaseStockDesc purchaseStockDesc , SupplierInfo supplierInfo , PurchaseStock purchaseStock){
        purchaseStockDesc.setSupplierInfo(supplierInfo);
        purchaseStockDesc.setPurchaseStock(purchaseStock);
        System.out.println("purchaseStockDesc="+purchaseStockDesc);
        List<PurchaseStockDesc> purchaseStockDescs = supplierServiceInter.searchStream(purchaseStockDesc);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",purchaseStockDescs.size());
        map.put("data",purchaseStockDescs);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*商品销售*/
    @RequestMapping(value = {"/searchSaleOrderDescController"})
    @ResponseBody
    public String searchSaleOrderDescController(SaleOrderDesc saleOrderDesc , SupplierInfo supplierInfo , PurchaseStock purchaseStock){
        saleOrderDesc.setSupplierInfo(supplierInfo);
        saleOrderDesc.setPurchaseStock(purchaseStock);
        List<SaleOrderDesc> saleOrderDescs = supplierServiceInter.searchSaleOrderDesc(saleOrderDesc);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",saleOrderDescs.size());
        map.put("data",saleOrderDescs);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    /*供货商财务*/
    @RequestMapping(value = {"/searchAccountingController"})
    @ResponseBody
    public String searchAccountingController( SupplierInfo supplierInfo ){
        List<SupplierInfo> supplierInfos = supplierServiceInter.searchAccounting(supplierInfo);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("count",supplierInfos.size());
        map.put("data",supplierInfos);
        String maps = JSON.toJSONString(map);
        return maps;
    }

    @RequestMapping(value = {"/taige"})
    @ResponseBody
    public int taige(PurchaseStock purchaseStock){
        int i = supplierServiceInter.updateStockRetreat(purchaseStock);
        return i;
    }
}